package com.itbomb.tvdemo;

import android.content.Context;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.support.v7.widget.AppCompatImageView;
import android.util.AttributeSet;

/**
 * @author A.D.Wilme
 * @date on 2018/8/27  14:02
 * @email A.D.Wilme@gmail.com
 * @describe 设置饱和度
 */
public class SaturationImageView extends AppCompatImageView {

    public SaturationImageView(Context context) {
        this(context, null);
    }

    public SaturationImageView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public SaturationImageView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public void setSaturation(float saturation) {
        ColorMatrix cm = new ColorMatrix();
        cm.setSaturation(saturation); // 设置饱和度:0为纯黑白，饱和度为0；1为饱和度为100，即原图；
        ColorMatrixColorFilter grayColorFilter = new ColorMatrixColorFilter(cm);
        this.setColorFilter(grayColorFilter);
    }

}
